import java.awt.Color;
import java.awt.Graphics;


public class IAPrac1CityMap extends javax.swing.JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 3125014386313048244L;
	private static int CITY_SIZE = 100;
	private static int GAP = 6;
	private int nusers;
	private int nconds;
	private int ncoord;
	private int[][] citymap;
	private int posinix = 30;
	private int posiniy = 30;
	
	public void setCityMap(int nu, int nc, int[][] reg, int nco) {
		nusers = nu;
		nconds = nco;
		ncoord = nc;
		citymap = new int[nusers][ncoord];
		
		for (int i = 0; i < nusers; ++i) {
			for (int j = 0; j < ncoord; ++j) {
				citymap[i][j] = reg[i][j];
			}
		}
		
		repaint();
	}
	
	public void paintComponent(Graphics g) {
		super.paintComponent(g);
		
		g.setColor(Color.black);
		for (int i = 0; i <= 10; ++i) {
	        g.drawLine(posinix + 0, posiniy + i*GAP*10, posinix + CITY_SIZE*GAP, posiniy + i*GAP*10);
	        g.drawString(i + "Km", posinix + i*GAP*10 - 2*GAP, posiniy - 2*GAP);
	        g.drawLine(posinix + i*GAP*10, posiniy + 0, posinix + i*GAP*10, posiniy + CITY_SIZE*GAP);
	    } 
		
		for (int i = 0; i < nconds; ++i) {
			g.setColor(Color.red);
			g.drawString("C" + i + "I", posinix + citymap[i][0]*GAP + 2*GAP, posiniy + citymap[i][1]*GAP + 2*GAP);
			g.fillRect(posinix + GAP*citymap[i][0], posiniy + GAP*citymap[i][1], GAP + 1, GAP + 1);
			g.drawString("C" + i + "F", posinix + citymap[i][2]*GAP + 2*GAP, posiniy + citymap[i][3]*GAP + 2*GAP);
			g.fillRect(posinix + GAP*citymap[i][2], posiniy + GAP*citymap[i][3], GAP + 1, GAP + 1);
		}
		
		for (int i = nconds; i < nusers; ++i) {
			g.setColor(Color.blue);
			g.drawString("P" + i + "I", posinix + citymap[i][0]*GAP + 2*GAP, posiniy + citymap[i][1]*GAP + 2*GAP);
			g.fillRect(posinix + GAP*citymap[i][0], posiniy + GAP*citymap[i][1], GAP + 1, GAP + 1);
			g.drawString("P" + i + "F", posinix + citymap[i][2]*GAP + 2*GAP, posiniy + citymap[i][3]*GAP + 2*GAP);
			g.fillRect(posinix + GAP*citymap[i][2], posiniy + GAP*citymap[i][3], GAP + 1, GAP + 1);
		}
		
		// Position check
		//g.setColor(Color.green);
		//g.fillRect(posinix + GAP*0, posiniy + GAP*0, GAP + 1, GAP + 1);
		//g.fillRect(posinix + GAP*99, posiniy + GAP*99, GAP + 1, GAP + 1);
		//g.fillRect(posinix + GAP*0, posiniy + GAP*99, GAP + 1, GAP + 1);
		//g.fillRect(posinix + GAP*99, posiniy + GAP*0, GAP + 1, GAP + 1);
	}
}
